<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<script type="text/javascript">
    /**
     * 自定义验证规则
     */
    function validateForm() {
        form.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                code: {
                    validators: {
                        notEmpty: {message: "物流公司代码不可为空"},
                        stringLength: {min: 2, max: 50, message: "物流公司代码长度为2至50"},
                        //regexp: {
                        //    regexp: validateUtil.onlyChar,
                        //    message: '只能填写字母'
                        //}
                    }
                },
                deliveryCorpName: {
                    validators: {
                        notEmpty: {message: "物流公司名称不可为空"},
                        stringLength: {max: 200, message: "物流公司名称最大长度为200"},
                        //regexp: {
                        //    regexp: validateUtil.chinese,
                        //   message: '只能输入中文'
                        //}
                    }
                },
                deliveryUrl: {
                    validators: {
                        notEmpty: {message: "物流公司网址不可为空"},
                        stringLength: {max: 200, message: "物流公司网址最大长度为200"},
                        //regexp: {
                        //    regexp: validateUtil.webUrl,
                        //    message: '请输入有效的物流公司网址'
                        //}
                    }
                },
                sortCode: {
                    validators: {
                        notEmpty: {message: "排序不可为空"},
                        stringLength: {min: 1, max: 10, message: "排序长度为1至10"},
                        numeric: {message: '只能输入数字'}
                    }
                }
            }
        });
    }

    /**
     * 添加物流公司信息
     */
	<shiro:hasPermission name="back_gotoLogisticsPage_add">
	function addInfo() {
        $("#myModalLabel").empty().text("添加物流公司信息");
        /**清空隐藏域的值**/
        $("#logisticsId").val("");
        $("#createDate").val("");
        resetAddForm();
    }
    </shiro:hasPermission>

    /**
     * 编辑物流公司信息
     */
	<shiro:hasPermission name="back_gotoLogisticsPage_update">
    function editInfo() {
        $("#myModalLabel").empty().text("修改物流公司信息");
        /**获取选中行的id**/
        var selectedRow = $("#tt").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            var id = selectedRow[0].logisticsId;
            $("#btn_edit").attr("data-target", "#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
            $.ajax({
                type: "POST",
                dataType: "JSON",
                url: "${basePath}/back/logistics/getLogisticsObject.sjson",
                data: {id: id},
                success: function (result) {
                    var data = JSON.parse(result.data);
                    /**隐藏域**/
                    $("#logisticsId").val(data.logisticsId);
                    $("#createDate").val(new Date(data.createDate).Format("yyyy-MM-dd hh:mm:ss"));
                    /**可见表单控件**/
                    $("#code").val(data.code);
                    $("#deliveryCorpName").val(data.deliveryCorpName);
                    $("#deliveryUrl").val(data.deliveryUrl);
                    $("#sortCode").val(data.sortCode);
                    $("#isCommon_" + data.isCommon).attr("checked", "checked");
                }
            });
        } else {
            $("#btn_edit").attr("data-target", "");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
    </shiro:hasPermission>
</script>
<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static" >
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel"></h5>
			</div>
			<div class="modal-body">
				<form id="form1"  method="post" action="${basePath}/back/logistics/saveOrUpdateLogistics.sjson">
					<input id="logisticsId" type="hidden" name="logisticsId" noclear="true"/>
					<input id="createDate" type="hidden" name="createDate" value=""/>

					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>物流公司代码:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="code" name="code" placeholder="请输入物流公司代码"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>物流公司名称:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="deliveryCorpName" name="deliveryCorpName" placeholder="请输入物流公司名称"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>物流公司网址:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="deliveryUrl" name="deliveryUrl" placeholder="请输入物流公司网址"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>排序:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="sortCode" name="sortCode" placeholder="请输入排序"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>是否常用:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<label class="checkbox-inline">
									<input type="radio" name="isCommon" id="isCommon_1" class="radioInput" value="1" checked="checked">&nbsp;经常用
								</label>
								<label class="checkbox-inline">
									<input type="radio" name="isCommon" id="isCommon_0" class="radioInput" value="0">&nbsp;不常用
								</label>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary"  onclick="submitForm()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
